package com.kika.obwiki.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import javax.websocket.server.ServerContainer;
import org.springframework.context.annotation.Profile;

/**
 * WebSocket配置类
 * 启用WebSocket支持
 */
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(ServerContainer.class) // 只有有websocket容器时才注册，彻底兼容所有环境
@Profile("!test") // 只在非test profile下注册，彻底兼容所有环境
public class WebSocketConfig {

  /**
   * 注入ServerEndpointExporter，
   * 这个bean会自动注册使用了@ServerEndpoint注解声明的websocket endpoint
   */
  @Bean
  public ServerEndpointExporter serverEndpointExporter() {
    return new ServerEndpointExporter();
  }

}